﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.ComplexClasses;
using DAL;
using App_Log;
using App_Utils;

namespace BLL
{
    public class BL_Contact
    {
        public static Contact SaveRecord(Contact objContact)
        {
            try
            {
                clsLog.logMsg("Contact", "SaveRecord", "Started");
                DAL.ithubEntities db = new ithubEntities();
                var query = (from q in db.tblContacts where q.contact_id == objContact.contact_id select q).SingleOrDefault();

                if (query != null)
                {
                    query = (tblContact)clsUtils.ConvertToObject(objContact, new tblContact());
                    db.SaveChanges();
                }
                else
                {
                    tblContact _objtblContact = new tblContact();
                    _objtblContact = (tblContact)clsUtils.ConvertToObject(objContact, new tblContact());
                    db.tblContacts.Add(_objtblContact);
                    db.SaveChanges();
                    objContact = (Contact)clsUtils.ConvertToObject(_objtblContact, objContact);
                }
            }
            catch (Exception ex)
            {
                clsLog.logError("Contact", "SaveRecord", ex.Message);
            }
            return objContact;
        }
    }
}
